﻿using _17bang.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace _17bang.Repositories
{
    public class UserRepository
    {
        private static IList<User> users;
        static UserRepository()
        {
            users = new List<User>
            {
                new User
                {
                    Id = 1,
                    Name = "小九",
                    Password = "1988",
                    InvitedByName = "胡胡",
                    InVitedByCode = "1997",
                }
            };
        }
        internal User Find(int id)
        {
            return users.Where(u => u.Id == id).SingleOrDefault();
        }
        internal User GetByInvitedName(string invitedname)
        {
            return users.Where(u => u.InvitedByName == invitedname).SingleOrDefault();
        }
        internal User GetByName(string name)
        {
            return users.Where(u => u.Name == name).SingleOrDefault();
        }
        public void Save(User user)
        {
            users.Add(user);
        }
    }
}
